<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <#assign base=request.contextPath  />
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${base}/js/layui/css/layui.css" media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
     <style type="text/css">
         form{
             padding: 20px;
         }
         .layui-btn-radius{
             border-radius: 5px;
         }
  </style>
</head>
<body>
<input type="hidden" id="homeID" value="${homeId}">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">周期</label>
            <div class="layui-input-inline">
                <select name="modules" lay-verify="required" class=" isNull" id="weedId" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>

            <label class="layui-form-label">餐点选择</label>
            <div class="layui-input-inline">
                            <select name="modules"  id="timeId" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                                <option value="早点">早点</option>
                                <option value="午点">午点</option>
                                <option value="晚点">晚点</option>
                                <option value="中餐">中餐</option>
                                <option value="晚餐">晚餐</option>
                            </select>
                        </div><br/><br/><br/>

            <label class="layui-form-label">菜品</label>
                     <div class="layui-input-inline"style="width:410px">
                         <select name="modules"  id="varietyId" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                          </select>
                     </div>
                      <button class="layui-btn layui-btn-radius" lay-submit lay-filter="formDemo" type="button" onclick="subFood()" style="background-color: #0092EF;">保存</button>

       </div>

        <table
                class="layui-table"
                lay-data="{url:'${base}/foodRelation/findFoodData',
                id:'test3',
                where:{'homeId':$('#homeID').val()},
                id:'testReload' ,
                height:200,
                page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] ,
                theme: '#0092EF',limit:20}
                }"
                lay-filter="test3">
            <thead>
            <tr>
                <th lay-data="{field:'eachtime'}">餐点</th>
                <th lay-data="{field:'foodName'}">菜品</th>
                <th lay-data="{field:'weedName',width: 180}">周期</th>
            </tr>
            </thead>
        </table>
    </div>
</form>
  <script src="${base}/js/layui/layui.js" charset="utf-8"></script>
  <script src="${base}/js/jquery.min.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
    });
    //获取添加时候的周期
    var bas = "${base}"
    //home:变量  = zhang.js里边封装的名称(路径,"字典表里边的code")
    var home_data = getDataByCode(bas,"LiliMenu")
    for(var i=0;i<home_data.length;i++){
        $("#weedId").append(
                '<option value="'+home_data[i].id+'">'+home_data[i].name+'</option>'
        )

    }
                             //获取菜品
                              $.ajax({
                                           type:"POST",
                                           url:"${base}/variety/selectVariety",
                                           async:false,//把异步改为同步
                                           success : function(data){
                                              for(var k=0;k<data.length;k++){
                                                 $("#varietyId").append(
                                                             '<option value="'+data[k].id+'">'+data[k].vegetable+'</option>'
                                                     )
                                                 }
                                           }
                                       });
    function subFood(){
        if(!isNull()){
            return
        }
        var requestData={};
        requestData.roomId=$("#homeID").val();
        requestData.weedId=$("#weedId").val();
        requestData.eachtime=$("#timeId").val();
        requestData.food=$("#varietyId").val();
        $.ajax({
            type:"POST",
            url:"${base}/foodRelation/insertFood",
            data:{"param":JSON.stringify(requestData)},
            success : function(data){
                 layer.msg(data);
                var table = layui.table;
                //表刷新方法
                table.reload('testReload', {
                    url: '${base}/foodRelation/findFoodData'
                    , where:{'homeId':$('#homeID').val()}//设定异步数据接口的额外参数
                });
            }
        });
    }
</script>

</body>
</html>